package com.zw.cc.stock.service;

import com.zw.cc.stock.model.vo.StocksVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * Created by zhaowuz on 2018/1/9
 */
@Service
public class QuotesTask {

    private static final Logger LOGGER = LoggerFactory.getLogger(QuotesTask.class);

    @Autowired
    private QuotesService quotesService;

    @Autowired
    private PolicyService policyService;

    @Scheduled(cron = "${quotes.task-cron}")
    public void updateQuotes() {
        LOGGER.info(">>>>>>>>更新每日行情开始");
        quotesService.updateQuotes();
        LOGGER.info(">>>>>>>>更新每日行情结束");
    }

    @Scheduled(cron = "${calculate.task-cron}")
    public void calculateTask() {
        LOGGER.info(">>>>>>>>计算开始");
        for(StocksVo stocksVo : policyService.getStocksVoList()) {
            policyService.calculate(stocksVo.getCode());
        }
        LOGGER.info(">>>>>>>>计算结束");
    }

}
